﻿using M.Warehouse.API.Application.Command.WarehousesCommand;
using M.Warehouse.Domain;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.WarehousesHandlers
{
    /// <summary>
    /// 返填仓库中介者
    /// </summary>
    public class WarehousesBackfillCommandHandlers : IRequestHandler<WarehousesBackfillCommand, Warehouses>
    {
        /// <summary>
        /// 仓库仓储接口
        /// </summary>
        private readonly IWarehouseWRepository _warehouseWRepository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="warehouseWRepository"></param>
        public WarehousesBackfillCommandHandlers(IWarehouseWRepository warehouseWRepository)
        {
            _warehouseWRepository = warehouseWRepository;
        }
        /// <summary>
        /// 返填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Warehouses> Handle(WarehousesBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _warehouseWRepository.GetAllAsync()).Where(x => x.WarehouseId == request.WarehouseId).FirstOrDefault();
        }
    }
}
